﻿
(function () {
    appModule.controller('tenant.views.parametertype.createOrEditParameterType', [
        '$scope', '$uibModalInstance', 'abp.services.app.parameterType', 'parameterTypeId', 'code',
        function ($scope, $uibModalInstance, parameterTypeService, parameterTypeId, code) {
            var vm = this;
            //类型管理中的类型及编码
            $scope.typeData = [
                {'name': '稿件类型', 'value': 1 },
                {'name': '栏目类型', 'value': 2 },
                {'name': '公告类型', 'value': 3 }
            ];
            switch (code) {
                case "1":
                    vm.Title = "稿件类型";
                    break;
                case "2":
                    vm.Title = "栏目类型";
                    break;
                case "3":
                    vm.Title = "公告类型";
                    break;
            }
            vm.saving = false;
            vm.parameterType = null;

            vm.save = function () {
                vm.saving = true;
                vm.parameterType.code = code;
                parameterTypeService.createOrUpdateParameterType({parameterType:vm.parameterType}).success(function () {
                    abp.notify.info(app.localize('SavedSuccessfully'));
                    $uibModalInstance.close();
                    vm.curParameterType = null;
                }).finally(function () {
                    vm.saving = false;
                });
            };

            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };
            function init() {
                parameterTypeService.getParameterTypeForEdit({
                    id: parameterTypeId
                }).success(function (result) {
                    vm.parameterType = result.parameterType;
                });
            }

            init();
        }
    ]);
})();
